<?php
Class Help_m extends CI_Model{

	function get_helps($module = ''){
		if($module)
			$this->db->where('module', $module);
		$this->db->where('trang_thai', 1);
		$this->db->order_by('sequence', 'ASC');
		$result = $this->db->get('help')->result();
		$return	= array();
		foreach($result as $help)
			$return[$help->id]	= $help;
		return $return;
	}

	function get_help($id){
		$this->db->where('id', $id);
		$result = $this->db->get('help')->row();
		return $result;
	}
	
	function get_slug($id){
		$help = $this->get_help($id);
		if($help) 
			return $help->slug;
	}
	
	function save($data){
		if($data['id']){
			$this->db->where('id', $data['id']);
			$this->db->update('help', $data);
			return $data['id'];
		}else{
			$this->db->insert('help', $data);
			return $this->db->insert_id();
		}
	}
	
	function delete_help($id){
		$this->db->where('id', $id);
		$this->db->delete('help');
	}
	
	function get_help_by_slug($slug){
		$this->db->where('slug', $slug)->where('trang_thai', 1);		
		$result = $this->db->get('help')->row();
		return $result;
	}
}